var statistics = function(type, id, yn, time, callback) {
         var UAParser = uaParserJs,
        parser = new UAParser(navigator.userAgent.toLocaleLowerCase()),
        Ua = parser.getResult();    

        var sta = {
            mos     : '',
            ua      : '',
            session : ''
        };


        function getDate() {
            var d = new Date(),
                toDouble = function(num) {
                    return num < 10 ? "0" + num : "" + num;
                },
                date = [
                    d.getFullYear() + '-', toDouble(d.getMonth() + 1) + '-', toDouble(d.getDate()) ],
                time = [ toDouble(d.getHours()) + ':', toDouble(d.getMinutes()) + ':', toDouble(d.getSeconds()) ];

            return {date: date, time: time};
        }

        var times  = getDate().date.join('') + '+' + getDate().time.join(''),
            curUrl = document.URL,
            refUrl = document.referrer,
            action = type, v = '',
            vid = id || 0, yn = yn || '';

        var version = Ua.os.version,
            name = Ua.os.name;

        var rid = '', _type = '';

        if(name == 'iOS') {
            if(!Ua.device.model || Ua.device.model != 'iphone') {
                name = 'iphone';
            }
            else {
                name = Ua.device.model;
            }
        }
        else if(name == 'blackberry' && !version) {
            version = '5.0';
        }
        else if(name == 'rim tablet os') {
            if(!version) version = '2.1.0';
        }
        else if(name == undefined) {
            name = 'android';
            version = '4.0.1';
        }
        else if(name == 'linux' || name == 'Linux') {
            version = '5.2';
        }

        sta.mos = name + '_' + version;
        
        if(action == 1) {
        	v = 'page';
        	sta.session = times + '#' + v + '#' + 'url=' + curUrl + '$ref=' + refUrl || '.';
        }
        // 下载app
        else if (action == 2) {
            _type = 'download';
            sta.session = times + '#action#' + 'type=' + _type;
        }
        // 微信分享
        else if(action == 3) {
            _type = 'share';
            sta.session = times + '#action#' + _type;   
        }
        
        callback && callback();

        $.ajax({
            type: "GET",
            url:"/index.php/api/debistat",
            data: {
                ua: name,
                mos: sta.mos,
                session: sta.session
            },
            error: function(){
                console.log("fail");
            }
        });

    };